package com.itWaiLong.AppException;

import com.itWaiLong.Result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 自定义全局异常捕获类
 */
@ControllerAdvice
public class DefinitionException {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result exception(Exception e) {
        if (e instanceof GlobalExceptionHandler es){
            return Result.defineFail(es);
        }
        System.out.println(e.getMessage()+e.getCause());
        return Result.fail("系统异常："+e.getMessage());
    }
}
